package dao.impl;

import dao.IUserLevelDao;
import jdbc_util.FirstApp;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import pojo.UserLevel;

import java.sql.SQLException;

public class UserLevelDaoImpl implements IUserLevelDao {

    @Override
    public UserLevel findIdByName(String name) {
        UserLevel userLevel = null;
        QueryRunner qr = null;
        try {
            String sql = "select * from userlevel where level =?";
            qr = new QueryRunner();
            userLevel = qr.query(FirstApp.getConn(), sql, new BeanHandler<>(UserLevel.class), name);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return userLevel;
    }

    @Override
    public UserLevel findByid(int id) {
        UserLevel userLevel = null;
        QueryRunner qr = null;
        try {
            String sql = "select * from userlevel where userlevelid =?";
            qr = new QueryRunner();
            userLevel = qr.query(FirstApp.getConn(), sql, new BeanHandler<>(UserLevel.class), id);
            return userLevel;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
